#include "BluetoothDeviceCell.h"

#include <QHBoxLayout>
#include <QBluetoothAddress>

BluetoothDeviceCell::BluetoothDeviceCell(QWidget *parent) : QWidget(parent)
{
    Init();
}

BluetoothDeviceCell::~BluetoothDeviceCell()
{
}

void BluetoothDeviceCell::SetHeader(const QString &name, const QString address, const QString &rssi)
{
    nameLabel->setText(name);
    addressLabel->setText(address);
    rssiLabel->setText(rssi);
}

void BluetoothDeviceCell::SetBluetoothDeviceInfo(const QBluetoothDeviceInfo &info)
{
    this->info = info;
    nameLabel->setText(info.name());
    addressLabel->setText(info.address().toString());
    rssiLabel->setText(QString::number(info.rssi()));
}

QBluetoothDeviceInfo BluetoothDeviceCell::GetBluetoothDeviceInfo() const
{
    return info;
}

void BluetoothDeviceCell::SetBluetoothUuid(const QBluetoothUuid &uuid)
{
    this->bluetoothUuid = uuid;
    addressLabel->setText(bluetoothUuid.toString());
}

QBluetoothUuid BluetoothDeviceCell::GetBluetoothUuid() const
{
    return bluetoothUuid;
}

void BluetoothDeviceCell::Init()
{
    setFixedHeight(30);
    auto mainLayout = new QHBoxLayout;
    nameLabel = new QLabel(this);
    addressLabel = new QLabel(this);
    rssiLabel = new QLabel(this);
    mainLayout->addWidget(nameLabel);
    mainLayout->addWidget(addressLabel);
    mainLayout->addWidget(rssiLabel);
    setLayout(mainLayout);
}
